import java.util.Scanner;
import java.util.Stack;

public class DAY7 {
    public boolean chkParenthesis(String A, int n) {
        // write code here
        if(n%2!=0){
            return false;
        }
        Stack<Character>stack=new Stack<>();
        for(char c:A.toCharArray()){
            if(c=='('){
                stack.push(c);
            } else if (c==')') {
                if(stack.isEmpty())
                    return false;
                else if (stack.peek()=='(') {
                    stack.pop();
                }
            }else {
                return false;
            }
        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int f1=0;
        int f2=1;
        while(n>f2){
            int f3=f1+f2;
            f1=f2;
            f2=f3;
        }
        int min=Math.min(n-f1,f2-n);
        System.out.println(min);

    }
}
